package com.bow.algorithm.structure;

/**
 * 泛型的PECS原則(producer extends, consumer super)
 * 如果你是想遍历collection，并对每一项元素操作时，此时这个集合是生产者（生产元素），应该使用 Collection <? extends T>.
 * 如果你是想添加元素到collection中去，那么此时集合是消费者（消费元素）应该使用Collection<? super T>
 * 
 * @author vv
 * @since 2018/9/2.
 */
public class RedBlackTree<AnyType extends Comparable<? super AnyType>> {

	private static final int BLACK = 1;
	private static final int RED = 0;

	private RedBlackNode<AnyType> header;
	private RedBlackNode<AnyType> nullNode;

	public RedBlackTree() {
		this.nullNode = new RedBlackNode<AnyType>(null);
		this.nullNode.left = nullNode;
		this.nullNode.right = nullNode;

		this.header = new RedBlackNode<AnyType>(null);
		this.header.left = nullNode;
		this.header.right = nullNode;
	}




	public void printTree() {

	}

	private void printTree(RedBlackNode<AnyType> t) {
		if (t != null) {
			printTree(t.left);
			System.out.println(t.element);
			printTree(t.right);
		}
	}

	private static class RedBlackNode<AnyType> {

		AnyType element;
		RedBlackNode<AnyType> left;
		RedBlackNode<AnyType> right;
		int color;

		RedBlackNode(AnyType theElement) {
			this(theElement, null, null);
		}

		RedBlackNode(AnyType theElement, RedBlackNode<AnyType> lt, RedBlackNode<AnyType> rt) {
			this.element = theElement;
			this.left = lt;
			this.right = rt;
			this.color = BLACK;
		}
	}
}
